package com.fhzn.boss.web.request;

import com.fhzn.commons.toolkit.exception.BuzException;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author 老顾
 * @apiNote
 * @since 2023/12/20
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ResourceQueryRequest extends BaseRequest {

    private Integer id;

    private String appCode;

    private String name;

    private String code;

    private String parentCode;

    private Integer level;

    private Integer resourceType;

    private Integer status;

    private String url;

    private Integer sort;

    /**
     * appCode集合,用于对权限做精细化的控制
     */
    private List<String> limitCodes;


    public void rewriteParams() {
        if (StringUtils.isBlank(name)) {
            this.setName(null);
        }
        if (StringUtils.isBlank(code)) {
            this.setCode(null);
        }
        if (StringUtils.isBlank(appCode)) {
            this.setAppCode(null);
        }
        if (StringUtils.isBlank(parentCode)) {
            this.setParentCode(null);
        }
    }

    public void checkId() {
        if (id == null) {
            throw new BuzException("id不能为空");
        }
    }

    public void checkParams() {
        this.checkBaseParams();
    }

    /**
     * 生成发往服务端的query对象
     */
    public Object genServiceParam() {
        throw new UnsupportedOperationException();
    }
}
